def results = Book.withCriteria {
def now = new Date()
between('releaseDate', now-7, now)
like('title', '%Groovy%')
}
withCriteria
方法允许在其内部定义Criteria,用于HibernateCriteriaBuilder的参数可以作为第一个参数被传入:
def book = Book.withCriteria(uniqueResult:true) { def now = new Date() between('releaseDate', now-7, now) like('title', '%Groovy%') }
arguments
(可选) - 命名参数map,用于设置criteria实例closure
- 定义criteria的闭包